package com.example.paopao.passport.config;

import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

@Slf4j
@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {

    private static final String BASE_PACKAGE="com.example.paopao";

    private static final String GROUP_NAME="泡泡网";

    private static final String HOST="http://paopao.com.example";

    private static final String TITLE="泡泡网-单点登录服务-在线API文档";

    private static final String DESCRIPTION="泡泡网-单点登录服务-在线API文档";

    private static final String TERMS_OF_SERVICE_URL="http://www.apache.org/licenses/LICENSE-2.0";

    private static final String CONTACT_NAME="xxx";

    private static final String CONTACT_URL="http://paopao.com.example";

    private static final String CONTACT_EMAIL="paopao@com.example";

    private static final String VERSION="1.0";

    @Autowired
    private OpenApiExtensionResolver openApiExtensionResolver;

    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .host(HOST)
                .apiInfo(apiInfo())
                .groupName(GROUP_NAME)
                .select()
                .apis(RequestHandlerSelectors.basePackage(BASE_PACKAGE))
                .paths(PathSelectors.any())
                .build()
                .extensions(openApiExtensionResolver.buildExtensions(GROUP_NAME));
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(TITLE)
                .description(DESCRIPTION)
                .termsOfServiceUrl(TERMS_OF_SERVICE_URL)
                .contact(new Contact(CONTACT_NAME, CONTACT_URL, CONTACT_EMAIL))
                .version(VERSION)
                .build();
    }
}
